package com.itheima.reggie.dao;

import com.itheima.reggie.entity.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface CategoryDao {

    @Insert("insert into category values(null,#{type},#{name},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void save(Category category);

    @Select("select * from category order by sort")
    List<Category> findAll();

    @Delete("delete from category where id = #{id}")
    void deleteById(Long id);

    @Update("update category set name = #{name},sort = #{sort},update_time = #{updateTime},update_user = #{updateUser} where id = #{id}")
    void update(Category category);


    /**
     * 作用：根据type查询类别的数据，注意：课程第六天还会调用list方法，但是那时候别人是不传递type给我，建议使用动态sql
     * @param type
     * @return
     */
    List<Category> list(@Param("type") Integer type);

    @Select("select * from category where id =#{categoryId} ")
    Category findById(Long categoryId);
}
